(function(win, $){
    var getEditorPT = win.getEditorPT = function() {
        var data = $('#service_intro').val();
        if(!data) {
            return [];
        }
        data = $.parseJSON(data);
        //console.log(data);
        return data;
    };
    var setEditorPT = win.setEditorPT = function(data) {
        //console.log(data);
        if($.isArray(data) && data.length > 0) {
            $('#service_intro').val(JSON.stringify(data));
            var viewObj = $('#box_intro_view');
            editorPTView(viewObj, data);
            $('#but_intro_update').removeClass('hide');
            $('#but_intro_add').addClass('hide');
        }
        layer.closeAll();
    };
    function showEditorPT() {
        layer.open({
            type: 2,
            title: '详细介绍编辑',
            shadeClose: false,
            shade: 0.8,
            area: ['1250px', '95%'],
            content: urlMap.editorPT + '?type=bpService'
        });
    }
    var setFormResult = win.setFormResult = function (data) {
        //console.log(data);
        layer.closeAll();
        if(data.status != 10000) {
            layer.alert(data.errmsg, {icon: 5});
        } else {
            layer.confirm('添加成功！', {icon: 6, title:'系统提示', btn: ['继续添加','查看列表']}, function(index){
                location.reload(true);
            }, function(index){
                location.href = urlMap.bpListService + '?id=' + bpId;
            });
        }
    }
    $(function(){
        $('#but_intro_add').on('click', showEditorPT);
        $('#but_intro_update').on('click', showEditorPT);
        $('#form_add').validator({
            rules: {
                decimal: function (element, params) {
                    //内部的this指向的是当前实例，可以直接调用所有方法，这里调用了test方法
                    return /^[0-9]+\.[0-9]{0,2}$/.test(element.value) || /^[0-9]+$/.test(element.value) || '请输入格式如: 12.59 或 12 的数字';
                }
            }
        });
        $('#form_add').on('valid.form', function(e, form){
            layer.load();
            form.submit();
        });
    });
})(window, jQuery);
